<?php

Raise::load('core.structure.RaiseQueue');

/**
 * TestCoreRaiseQueue class
 * Testing unit of 'phpraise/control/RaiseQueue.php'
 *
 * @author Sam-Mauris Yong / hellclanner at live dot com
 * @license http://www.opensource.org/licenses/bsd-license New BSD License
 * @package Raise.UnitTest.Test
 */
class TestCoreRaiseQueue extends RaiseTest {

    public static function testClass(){
        self::assertClassExists('RaiseQueue');
        self::assertClassExtends('RaiseQueue', 'RaiseDataType');

        $queue = new RaiseQueue();
        self::assertObjectClass($queue, 'RaiseQueue');

        self::assertClassMethod($queue, 'enqueue');
        self::assertClassMethod($queue, 'dequeue');
        self::assertClassMethod($queue, 'count');
        self::assertClassMethod($queue, 'front');
    }

    public static function testOps(){
        $queue = new RaiseQueue();
        $queue->enqueue(20);

        self::assertStrictEqual($queue->front(), 20);
        self::assertStrictEqual($queue->count(), 1);

        $queue->enqueue(50);
        $queue->enqueue(90);

        self::assertStrictEqual($queue->front(), 20);
        self::assertStrictEqual($queue->count(), 3);

        $a = $queue->dequeue();
        self::assertStrictEqual($a, 20);
        self::assertStrictEqual($queue->front(), 50);
        self::assertStrictEqual($queue->count(), 2);

        $a = $queue->dequeue();
        self::assertStrictEqual($a, 50);
        self::assertStrictEqual($queue->front(), 90);
        self::assertStrictEqual($queue->count(), 1);

        $a = $queue->dequeue();
        self::assertStrictEqual($a, 90);
        self::assertStrictEqual($queue->count(), 0);

        self::assertNull($queue->dequeue());
        self::assertNull($queue->front());
    }

}